package cn.yfxu.server.controller;


import cn.yfxu.server.pojo.Result;
import cn.yfxu.server.pojo.Salary;
import cn.yfxu.server.service.ISalaryService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author yfxu
 * @since 2021-03-15
 */
@RestController
@RequestMapping("/salary/sob")
public class SalaryController {

    @Autowired
    private ISalaryService salaryService;

    @ApiOperation(value = "获取所有员工账套")
    @RequestMapping(method = RequestMethod.GET, value = "/")
    public List<Salary> getAllSalaries() {
        return salaryService.list();
    }

    @ApiOperation(value = "添加工资账套")
    @RequestMapping(method = RequestMethod.POST, value = "/")
    public Result addSalary(@RequestBody Salary salary){
        salary.setCreatedate(LocalDateTime.now());
        if (salaryService.save(salary)){
            return Result.success("添加成功!");
        }
        return Result.error("添加失败！");
    }
    @ApiOperation(value = "删除工资账套")
    @RequestMapping(method = RequestMethod.DELETE, value = "/{id}")
    public Result deleteSalary(@PathVariable Integer id){
        if (salaryService.removeById(id)){
            return Result.success("删除成功!");
        }
        return  Result.error("删除失败!");
    }
    @ApiOperation(value = "更新工资账套")
    @RequestMapping(method = RequestMethod.PUT, value = "/")
    public Result updateSalary(@RequestBody Salary salary){
        if (salaryService.updateById(salary)){
            return Result.success("更新成功!");
        }
        return  Result.error("更新失败!");
    }

}
